#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
struct ListNode {
int val;
struct ListNode* next;
};
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
    struct ListNode* src1 = list1;
    struct ListNode* src2 = list2;
    struct ListNode* newhead = NULL;
    struct ListNode* tail = NULL;
    if (list1 == NULL)
    {
        return list2;
    }
    if (list2 == NULL)
    {
        return list1;
    }
    newhead = tail = (struct ListNode*)malloc(sizeof(struct ListNode));
    while (src1 && src2)
    {
        if (src1->val >= src2->val)
        {
            tail->next = src2;
            tail = src2;
            src2 = src2->next;
        }
        else {
            tail->next = src1;
            tail = src1;
            src1 = src1->next;
        }
    }
    if (src1 == NULL)
    {
        tail->next = src2;
    }

    if (src2 == NULL)
    {
        tail->next = src1;
    }
    return newhead->next;
}